<template>
  <div>
    <div id="container">
      <el-card class="box-card" id="box">
        <el-menu
            :default-active="activeIndex"
            class="el-menu-demo"
            mode="horizontal"
            style="margin-bottom: 20px"
            @select="handleSelect">
          <el-menu-item index="1">文件上传</el-menu-item>
          <el-menu-item index="2" v-show="adminOpen">用户管理</el-menu-item>
        </el-menu>
        <component :is="conName"></component>
      </el-card>
    </div>
  </div>
</template>

<script>
import fileIO from "@/components/mainpage/fileIO.vue";
import account from "@/components/mainpage/account.vue";

export default {
  name: "system",
  components: {
    fileIO,
    account
  },
  data() {
    return{
      conName: 'fileIO',
      activeIndex: '1',
      adminOpen: false
    }
  },
  created() {
    this.adminOpen = "true" === this.$cookies.get("admin"); // 解析
    console.log("是否为admin",this.adminOpen)
  },
  provide() {
    return {
      refreshAdmin: this.refreshAdmin,
      setComponent: this.setComponent,
    };
  },
  methods: {
    handleSelect(key) {
      switch (key){
        case '1':
          this.conName = 'fileIO'
          break;
        case '2':
          this.conName = 'account'
          break;
      }
    },
    refreshAdmin(){
      this.adminOpen = "true" === this.$cookies.get("admin"); // 解析
    },
    setComponent(component) {
      this.conName = component
    }
  }
}
</script>

<style scoped>
#container{
  padding-top: 70px;
}
#box{
  margin: 0 auto;
  width: 90%;
  height: 90%;
}
</style>